package uit.mmt02.activity;

import uit.mmt02.R;
import uit.mmt02.share.OneMail;
import uit.mmt02.share.showToast;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageButton;
import android.widget.TextView;

public class readmailActivity extends Activity
{
	showToast st ;
	
	final static String KEY_SUB = "SUB";
	final static String KEY_FROM = "FROM";
	final static String KEY_TO = "TO";
	final static String KEY_TIME = "TIME";
	final static String KEY_BODY = "BODY";
	final static String KEY_FAVORITE = "FAVORITE";
	final static String KEY_BUNDLE = "BUNDLE";
	TextView txtsub, txtfrom, txtto, txttime, txtbody;
    CheckBox cb_favorite;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
	    
	    
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.read_mail);
		st = new showToast(getBaseContext());
		OneMail mail = new OneMail();
		Bundle bundle = getIntent().getExtras(); //bunder nhan du lieu tu listmail gui toi
		if(bundle.size() > 0)
		{
			Log.i("bundle", "bundle > 0");
			mail.setSub(bundle.getString(KEY_SUB));
			mail.setFrom(bundle.getString(KEY_FROM));
			mail.setTo(bundle.getString(KEY_TO));
			mail.setDateSend(bundle.getString(KEY_TIME));
			mail.setBody(bundle.getString(KEY_BODY));
			
			txtsub = (TextView)findViewById(R.id.txt_readmail_sub);
			txtfrom = (TextView)findViewById(R.id.txt_readmail_from);
			txtto = (TextView)findViewById(R.id.txt_readmail_to);
			txttime = (TextView)findViewById(R.id.txt_readmail_time);
			txtbody = (TextView)findViewById(R.id.txt_readmail_body);
			
			txtsub.setText(mail.getSub());
			txtfrom.setText(mail.getFrom());
			txtto.setText(mail.getTo());
			txttime.setText(mail.getDateSend());
			txtbody.setText(mail.getBody());
		}
		
	};
	
	public void btn_onClick(View v)
	{
		Button  btn = (Button)v;
		switch (btn.getId()) {
		case R.id.btn_readmail_reply:
			st.showmess("reply");
			Intent ii = new Intent("uit.mmt02.activity.newmailActivity");
			Bundle bundle = new Bundle();
			bundle.putString(KEY_TO, txtfrom.getText().toString());
			bundle.putString(KEY_BODY, txtbody.getText().toString());
			bundle.putString(KEY_SUB, txtsub.getText().toString());
			ii.putExtras(bundle);
			Log.v("read mailA","readmail call reply 0");
			startActivity(ii);
			Log.v("read mailA","readmail call reply 1");
			break;
		case R.id.btn_readmail_forward:
			st.showmess("4word");
			break;
			
		default:
			break;
		}
	}
	

	public void img_onClick(View v)
	{
		ImageButton img = (ImageButton)v;
		switch (img.getId()) {
		case R.id.btn_readmail_unlock:
			st.showmess("un lock");
			break;
		case R.id.img_readmail_next:
			st.showmess("next");
			break;
		case R.id.img_readmail_back:
			st.showmess("back");
			break;

		default:
			break;
		}
	}
	

}
